import { IFeidaoAiMobile } from '@dfeidao/atom-mobile/interfaces';
import get from '@dfeidao/atom-mobile/local/get';
import remove from '@dfeidao/atom-mobile/local/remove';
import set from '@dfeidao/atom-mobile/local/set';
import nodejs from '@dfeidao/atom-mobile/msg/nodejs';
import toast from '@dfeidao/atom-mobile/msgbox/toast';


export default async function a005(fd: IFeidaoAiMobile) {
	// 保存
	const d = get(fd, 'data') as { sex: string, sexing: string, birthday: number, brtime: string, mail_box: string };
	const teacher_no = get(fd, 'teacher_no');
	const productid = get(fd, 'productid');

	const obj = {} as {
		sex: string,
		mail_box: string,
		birthday: number
	};
	obj.sex = d.sex;
	obj.birthday = d.birthday;

	// const users = get(fd, 'users') as {
	// 	user_name: string;
	// 	usercode: string;
	// 	productid: string;
	// };
	// const teacher_no = get(fd, 'teacher_no');
	// const username = '李笑话';
	// const usercode = users.usercode;
	// const productid = users.productid;
	// const productid = 'teach_sys';

	const reg1 = new RegExp(/^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/);// 邮箱
	if (d.mail_box !== undefined && d.mail_box !== '') {
		if (!reg1.test(d.mail_box)) {
			await toast({
				type: 'danger',
				text: '邮箱格式错误',
				position: 'top'
			});
			return;
		}
	}
	if (get(fd, 'prevent')) {
		return;
	}
	set(fd, 'prevent', 1);

	if (d.mail_box) {
		obj.mail_box = d.mail_box;
	}
	if (JSON.stringify(obj) === '{}') {
		await toast({
			type: 'success',
			text: '无更改操作',
			position: 'top'
		});
		remove(fd, 'prevent');
		return;
	}

	// console.log(obj);
	const res = await nodejs<{ code: number }>('app-basic-information/s002', { obj, teacher_no, productid });
	remove(fd, 'prevent');
	if (res.code === 1) {
		await toast({
			type: 'success',
			text: '保存成功',
			position: 'top'
		});
	}
}




